{layout name="public/layout" /}
<!-- 内容主体区域 -->
<div class="site-block">
    <blockquote class="layui-elem-quote">
            <span class="layui-breadcrumb" lay-separator=">">
                <a href="">首页</a>
                <a><cite>添加广告</cite></a>
            </span>
    </blockquote>
    <fieldset class="layui-elem-field">
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label">广告名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="ad_name" required="" lay-verify="required" placeholder="请输入广告名称" autocomplete="off" class="layui-input" value="{$adconfFind.ad_name?:''}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">投放范围</label>
                    <div class="layui-input-inline">
                        <select name="ad_type" lay-filter="aihao">
                            <option value=""></option>
                            {volist name="ad_type" id="vo"}
                            <?php if(isset($adconfFind['ad_type'])){?>

                            <option {if condition="$vo['id'] eq $adconfFind['ad_type']"}selected='' {/if} value="{$vo.id}">{$vo.tp_name}</option>
                            <?php }else{?>
                            <option value="{$vo.id}">{$vo.tp_name}</option>
                            <?php }?>
                            {/volist}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">时间限制</label>
                    <div class="layui-input-block">
                        <?php if(isset($adconfFind["ad_time_type"])){?>
                        <input type="radio" name="ad_time_type" value="2" title="永不过期" {eq name='$adconfFind["ad_time_type"]?:""' value="1"}checked{/eq}>
                        <input type="radio" name="ad_time_type" value="1" title="在设内时间内有效" {eq name='$adconfFind["ad_time_type"]' value="2"}checked{/eq}>
                        <?php }else{?>
                        <input type="radio" name="ad_time_type" value="2" title="永不过期" checked>
                        <input type="radio" name="ad_time_type" value="1" title="在设内时间内有效">
                        <?php }?>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">开始投放</label>
                        <div class="layui-input-inline">
                            <input type="text" name="ad_g" class="layui-input" id="test-limit1" placeholder="yyyy-MM-dd" value="{$adconfFind.ad_g?:''}">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">结束投放</label>
                        <div class="layui-input-inline">
                            <input type="text" name="ad_o" class="layui-input" id="test-limit2" placeholder="yyyy-MM-dd" value="{$adconfFind.ad_o?:''}">
                        </div>
                    </div>
                </div>
                <div class="layui-tab layui-tab-card">
                    <ul class="layui-tab-title">
                        <li class="layui-this">文字</li>
                        <li>图片</li>
                        <li>代码</li>
                    </ul>
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <div class="layui-form-item">
                                <label class="layui-form-label">文字内容</label>
                                <div class="layui-input-block">
                                    <input type="text" name="ad_text_title" placeholder="请输入文字内容" autocomplete="off" class="layui-input" value="{$adconfFind.ad_text_title?:''}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">文字链接</label>
                                <div class="layui-input-block">
                                    <input type="text" name="ad_text_a" placeholder="请输入文字链接" autocomplete="off" class="layui-input" value="{$adconfFind.ad_text_a?:''}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">文字颜色</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="ad_text_color" placeholder="请输入文字颜色" autocomplete="off" class="layui-input" value="{$adconfFind.ad_text_color?:''}">
                                </div>
                                <div class="layui-form-mid layui-word-aux">(例如:red,#EF8684)</div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">文字大小</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="ad_text_size"  placeholder="请输入文字大小" autocomplete="off" class="layui-input" value="{$adconfFind.ad_text_size?:''}">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">(例如:4px,12px)</div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-form-item">
                                <label class="layui-form-label">图片地址</label>
                                <div class="layui-input-inline layui-upload">
                                    <button type="button" class="layui-btn yh_fl" id="test1"><i class="layui-icon"></i>上传图片</button>
                                </div>
                                <input class="layui-input layui-btn-disabled" name="ad_img" id="ad_img" style="line-height: 36px;width: 50%;" type="hidden" value="{$adconfFind.ad_img?:''}" />

                                <div class="layui-form-mid layui-word-aux" id="demo1">{$adconfFind.ad_img?:'还没有图片地址'}</div>
                            </div>
                            <script>
                                layui.use('upload', function(){
                                    var $ = layui.jquery
                                            ,upload = layui.upload;

                                    //普通图片上传
                                    var uploadInst = upload.render({
                                        elem: '#test1' //绑定元素
                                        ,accept:'file'
                                        ,url: '{:url("Common/uploadTicketFile")}' //上传接口
                                        ,done: function(res){
                                            if(res.code==1){
                                                layer.msg(res.msg,{time:500},function(){


                                                    $('#ad_img').val(res.imgUrl);
                                                    $('#demo1').html(res.imgUrl);


                                                })
                                            }else{
                                                layer.msg(res.msg,function(){})
                                            }
                                        }
                                        ,error: function(){
                                            //请求异常回调
                                        }
                                    });

                                });
                            </script>
                            <div class="layui-form-item">
                                <label class="layui-form-label">图片链接</label>
                                <div class="layui-input-block">
                                    <input type="text" name="ad_img_a" required="" placeholder="请输入图片地址" autocomplete="off" class="layui-input" value="{$adconfFind.ad_img_a?:''}">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">图片宽度</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="ad_img_w" required="" placeholder="请输入图片地址" autocomplete="off" class="layui-input" value="{$adconfFind.ad_img_w?:''}">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">宽度默认100%</div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">图片高度</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="ad_img_h" required="" placeholder="请输入图片地址" autocomplete="off" class="layui-input" value="{$adconfFind.ad_img_h?:''}">
                                    </div>
                                    <div class="layui-form-mid layui-word-aux">高度默认100%</div>

                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">图片描述</label>
                                <div class="layui-input-block">
                                    <textarea placeholder="请输入图片描述" name="ad_img_miao" class="layui-textarea">{$adconfFind.ad_img_miao?:''}</textarea>

                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">广告代码</label>
                                <div class="layui-input-block">
                                    <textarea placeholder="请填写广告代码，支持html代码" name="ad_text" class="layui-textarea">{$adconfFind.ad_text?:''}</textarea>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">过期显示内容</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入过期显示内容" name="ad_over_time" class="layui-textarea">{$adconfFind.ad_over_time?:''}</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="formDemo">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
                <input type="hidden" name="id" value="{$adconfFind.id?$adconfFind.id:''}"/>
            </form>
        </div>
    </fieldset>
</div>
<script>
    //Demo
    layui.use('element', function(){
        var element = layui.element;

        //…
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#test-limit1'
            ,theme: 'molv'
            ,type: 'datetime'
            ,min:0
        });
        laydate.render({
            elem: '#test-limit2'
            ,theme: 'molv'
            ,type: 'datetime'
            ,min: 1
        });
    });
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(datas){
            var url = "{:url('Ad/adconf')}";
            $.ajax({
                url: url,//POST给检测数据
                type: 'post',
                data:datas.field,
                dataType: 'json',

            }).done(function(res) {
                if(res.code==0){
				layer.alert(JSON.stringify(datas.field));
                    //有错抖一抖效果
                    <!-- layer.msg(res.msg,function(){}); -->
                }else{
                    layer.alert(res.msg,function(index){
                        layer.close(index);
                        window.location.href=res.url;

                    });
                }
            }).fail(function() {
                //实现抖一抖效果
                 layer.msg('系统异常，请稍后再试',function(){});
//				layer.alert(JSON.stringify(datas.field));
            });
            return false;
        });
    });
</script>